//
//  TKIMAccountStyle2TableViewCell.m
//  test2
//
//  Created by TryHone on 17/1/16.
//  Copyright © 2017年 TryHone. All rights reserved.
//

#import "TKIMAccountStyle2TableViewCell.h"

@implementation TKIMAccountStyle2TableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


+(instancetype)cellWithTableView:(UITableView *)tableView{
    
    TKIMAccountStyle2TableViewCell*  cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([self class])];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([self class])];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.backgroundColor=[UIColor whiteColor];
    }
    return cell;
}

#pragma mark - 初始化方法
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubViews];
    }
    return self;
}

-(void)addAllSubViews{
    [self.contentView addSubview:self.ico];
    [self.contentView addSubview:self.name];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat width = self.frame.size.width;
    CGFloat height = self.frame.size.height;
    CGFloat margin = 10;
    _ico.frame = CGRectMake(margin, 7, 30, 30);
    _name.frame = CGRectMake(CGRectGetMaxX(_ico.frame)+margin, 0, width-30-3*margin, height);
}


-(void)setDatamodle:(TKIMAccountModel *)datamodle{
    _datamodle=datamodle;
    
    if (_datamodle.leftimagename && _datamodle.leftimagename.length) {
        
      [self.ico sd_setImageWithURL:[[NSURL alloc] initWithString:_datamodle.leftimagename] placeholderImage:[UIImage imageNamed:_datamodle.leftimagename]];
    }
    self.name.text = _datamodle.lefttitle;

}


#pragma mark--懒加载
-(UIImageView*)ico{
    if (_ico == nil) {
        _ico = [[UIImageView alloc]init];
//        _ico.backgroundColor=[UIColor redColor];
    }
    return _ico;
}

-(UILabel*)name{

    if (_name == nil) {
        _name = [[UILabel alloc] init];
        
    }
    return _name;
}

@end
